'use strict';

const await = require('await-stream-ready/lib/await');

const Service = require('egg').Service;

class ScoreService extends Service {
  async searchScore(username, exam_id) {
    console.log('5555555555555555555555555',username);
    const { ctx, app } = this
    let user = await app.model.User.findOne({
      where: {
        username
      }
    })
    user = JSON.parse(JSON.stringify(user))
    console.log(user)
    
    let score = await app.model.Score.findAll({
      include: [
        { model: this.ctx.model.User },
        { model: this.ctx.model.Class },
        { model: this.ctx.model.Branch },
      ],
      where:{
        // branch_id,
        exam_id,
        user_id:user.id
      },
    });
    if(score.length === 0){
      return null
    }
    score = JSON.parse(JSON.stringify(score))
    console.log(score)

    return score ? score : null;
  }
}

module.exports = ScoreService;
